package com.mao.model.voucher;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;

import org.apache.struts2.json.annotations.JSON;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Type;

import com.mao.model.BaseModel;
import com.mao.model.organization.Organization;
import com.mao.model.user.User;
import com.mao.model.warehouse.WareHouse;

@MappedSuperclass
public class VoucherBase extends BaseModel {

	private static final long serialVersionUID = 1L;

	public Long id;

	public String no; // 自定义编号

	public BigDecimal transactionAmount = new BigDecimal(0); // 成交金额

	public BigDecimal receiveAmount = new BigDecimal(0); // 收款金额

	public String note;

	public Date datetime;

	public Date updatetime;

	public Organization org;

	public WareHouse wareHouse;

	public String voucherNo; // CGRKD/02/20120817/0001

	public VoucherType voucherType;

	public Integer proAmount = 0; // 这张单据的商品总量

	public BigDecimal totalPrice = new BigDecimal(0); // 这张单据的总价

	private Set<ProductDeliveryVoucher> proDeliverySet; // 销售出库单中间表

	private Set<ProductWareHouseVoucher> proWareHouseSet; // 采购入库单中间表

	private Set<ProductReturnDeliveryVoucher> proRetnDeliverySet; // 销售退货单中间表

	private Set<ProductReturnWareHouseVoucher> proRetnWareHouseSet; // 采购退货单中间表

	private VoucherVerityType isverity = VoucherVerityType.notverity; // 0 未审 1
																		// 已审

	private User user;

	@Id
	@GeneratedValue
	@Column(name = "ID")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "NO")
	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	@Column(name = "NOTE", columnDefinition = "TEXT")
	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	@Column(name = "TRANSACTIONAMOUNT", scale = 2, nullable = false)
	public BigDecimal getTransactionAmount() {
		return transactionAmount;
	}

	public void setTransactionAmount(BigDecimal transactionAmount) {
		this.transactionAmount = transactionAmount;
	}

	@Column(name = "RECEIVEAMOUNT", scale = 2, nullable = false)
	public BigDecimal getReceiveAmount() {
		return receiveAmount;
	}

	public void setReceiveAmount(BigDecimal receiveAmount) {
		this.receiveAmount = receiveAmount;
	}

	@Column(name = "DATETIME")
	public Date getDatetime() {
		return datetime;
	}

	public void setDatetime(Date datetime) {
		this.datetime = datetime;
	}

	@ManyToOne(optional = true, fetch = FetchType.LAZY)
	@JoinColumn(name = "ORGANIZATION", nullable = false, columnDefinition = "int")
	@JSON(serialize = false)
	public Organization getOrg() {
		return org;
	}

	public void setOrg(Organization org) {
		this.org = org;
	}

	@ManyToOne(optional = true, fetch = FetchType.LAZY)
	@JoinColumn(name = "WAREHOUSE", nullable = false, columnDefinition = "int")
	@JSON(serialize = false)
	public WareHouse getWareHouse() {
		return wareHouse;
	}

	public void setWareHouse(WareHouse wareHouse) {
		this.wareHouse = wareHouse;
	}

	@Column(name = "VOUCHERNO", nullable = false)
	public String getVoucherNo() {
		return voucherNo;
	}

	public void setVoucherNo(String voucherNo) {
		this.voucherNo = voucherNo;
	}

	@Type(type = "com.mao.model.voucher.VoucherTypeUserType")
	@Column(name = "VOUCHERTYPE")
	public VoucherType getVoucherType() {
		return voucherType;
	}

	public void setVoucherType(VoucherType voucherType) {
		this.voucherType = voucherType;
	}

	// 中间表set

	@OneToMany(cascade = javax.persistence.CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "voucher")
	@BatchSize(size = 50)
	public Set<ProductDeliveryVoucher> getProDeliverySet() {
		return proDeliverySet;
	}

	public void setProDeliverySet(Set<ProductDeliveryVoucher> proDeliverySet) {
		this.proDeliverySet = proDeliverySet;
	}

	@OneToMany(cascade = javax.persistence.CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "voucher")
	@BatchSize(size = 50)
	public Set<ProductWareHouseVoucher> getProWareHouseSet() {
		return proWareHouseSet;
	}

	public void setProWareHouseSet(Set<ProductWareHouseVoucher> proWareHouseSet) {
		this.proWareHouseSet = proWareHouseSet;
	}

	@OneToMany(cascade = javax.persistence.CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "voucher")
	@BatchSize(size = 50)
	public Set<ProductReturnDeliveryVoucher> getProRetnDeliverySet() {
		return proRetnDeliverySet;
	}

	public void setProRetnDeliverySet(
			Set<ProductReturnDeliveryVoucher> proRetnDeliverySet) {
		this.proRetnDeliverySet = proRetnDeliverySet;
	}

	@OneToMany(cascade = javax.persistence.CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "voucher")
	@BatchSize(size = 50)
	public Set<ProductReturnWareHouseVoucher> getProRetnWareHouseSet() {
		return proRetnWareHouseSet;
	}

	public void setProRetnWareHouseSet(
			Set<ProductReturnWareHouseVoucher> proRetnWareHouseSet) {
		this.proRetnWareHouseSet = proRetnWareHouseSet;
	}

	@Column(name = "UPDATETIME")
	public Date getUpdatetime() {
		return updatetime;
	}

	public void setUpdatetime(Date updatetime) {
		this.updatetime = updatetime;
	}

	@Type(type = "com.mao.model.voucher.VoucherVerityTypeUserType")
	@Column(name = "ISVERITY")
	public VoucherVerityType getIsverity() {
		return isverity;
	}

	public void setIsverity(VoucherVerityType isverity) {
		this.isverity = isverity;
	}

	@ManyToOne(optional = true, fetch = FetchType.LAZY)
	@JoinColumn(name = "USER", nullable = false, columnDefinition = "int")
	@JSON(serialize = false)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "PROAMOUNT", nullable = false)
	public Integer getProAmount() {
		return proAmount;
	}

	public void setProAmount(Integer proAmount) {
		this.proAmount = proAmount;
	}

	@Column(name = "TOTALPRICE", scale = 2, nullable = false)
	public BigDecimal getTotalPrice() {
		return totalPrice;
	}

	public void setTotalPrice(BigDecimal totalPrice) {
		this.totalPrice = totalPrice;
	}

}
